﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Borton.Beans;

namespace Borton
{
    class ControlManager
    {
        
        public static Label createLabel(Field field)
        {
            Label label = new Label();
            label.Text = getLabelText(field);
            label.Name = field.columnName + "Label";
            label.Size = new System.Drawing.Size(100, 20);
            label.TextAlign = ContentAlignment.MiddleRight;
            return label;
        }

        public static DataGridViewTextBoxColumn createColumn(Field field)
        {
            DataGridViewTextBoxColumn column = new System.Windows.Forms.DataGridViewTextBoxColumn();
            column.HeaderText = getLabelText(field);
            column.Name = field.columnName + "Column";
            column.ReadOnly = true;
            return column;
        }


        private static String getLabelText(Field field)
        {
            return field.columnName;
        }

        public static BeanStripButton createBeanStripButton(String text, Bean bean)
        {
            BeanStripButton btn = new BeanStripButton();
            try
            {
                btn.Image = ((System.Drawing.Image)(Properties.Resources.ResourceManager.GetObject(text.ToLower())));
                btn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
            }
            catch (System.Resources.MissingManifestResourceException) {
                btn.DisplayStyle = ToolStripItemDisplayStyle.Text;
            }
            btn.ImageTransparentColor = System.Drawing.Color.Magenta;
            btn.Name = text + "Btn";
            btn.Size = new System.Drawing.Size(23, 22);
            btn.Text = text;
            if (bean != null) {
                btn.bean = bean;
            }
            return btn;
        }

        public static ToolStripButton createToolbarButton(String text)
        {
            return (ToolStripButton)createBeanStripButton(text, null);
        }
    }
}
